//
//  HeaderViewSty1.m
//  EducationAdminClient
//
//  Created by kwsdzjx on 16/9/26.
//  Copyright © 2016年 周佳兴. All rights reserved.
//

#import "HeaderViewSty1.h"
#import "Masonry.h"
#import "UIColor+CL.h"
#import "MyButtonMainPage.h"

@implementation HeaderViewSty1

-(instancetype)initWithDelegate:(id)delegate{
    self = [super init];
    if (self) {
        
        _delegate = delegate;
        
        [self createCollectionViewHeaderView];
    }
    
    return self;
}
-(UIView *)createCollectionViewHeaderView{
    
    UIView *StuSuperView = self;
    
    UIView *baseView = [[UIView alloc]init];
    baseView.backgroundColor = [UIColor whiteColor];
    
    [StuSuperView addSubview:baseView];
    [baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(200/2));
        make.left.equalTo(StuSuperView.mas_left);
        make.right.equalTo(StuSuperView.mas_right);
        make.top.equalTo(StuSuperView.mas_top);
    }];
    MyButtonMainPage *myBtn = [[MyButtonMainPage alloc]init];
    myBtn.Btntag = 0;
    [baseView addSubview:myBtn];
    
    MyButtonMainPage *myBtn1 = [[MyButtonMainPage alloc]init];
    myBtn1.Btntag = 1;
    [baseView addSubview:myBtn1];
    
    MyButtonMainPage *myBtn2 = [[MyButtonMainPage alloc]init];
    myBtn2.Btntag = 2;
    [baseView addSubview:myBtn2];
    
    MyButtonMainPage *myBtn3 = [[MyButtonMainPage alloc]init];
    myBtn3.Btntag = 3;
    [baseView addSubview:myBtn3];
    
    [myBtn setTitle:@"扫码考勤" forState:UIControlStateNormal];
    [myBtn1 setTitle:@"报表管理" forState:UIControlStateNormal];
    [myBtn2 setTitle:@"消息提醒" forState:UIControlStateNormal];
    [myBtn3 setTitle:@"系统设置" forState:UIControlStateNormal];
    
    
    
    myBtn.titleLabel.font = [UIFont systemFontOfSize:28/2];
    myBtn1.titleLabel.font = [UIFont systemFontOfSize:28/2];
    myBtn2.titleLabel.font = [UIFont systemFontOfSize:28/2];
    myBtn3.titleLabel.font = [UIFont systemFontOfSize:28/2];
    
    [myBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [myBtn1 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [myBtn2 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [myBtn3 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    [myBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(baseView.mas_left).offset(0);
        make.width.equalTo(myBtn1.mas_width);
        make.height.equalTo(@((190)/2));
        make.top.equalTo(StuSuperView.mas_top);
        //             make.bottom.equalTo(baseView.mas_bottom).offset(-20);
        
    }];
    [myBtn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(myBtn.mas_right);
        make.width.equalTo(myBtn.mas_width);
        make.height.equalTo(myBtn.mas_height);
        make.bottom.equalTo(myBtn.mas_bottom);
    }];
    
    [myBtn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(myBtn1.mas_right);
        make.width.equalTo(myBtn1.mas_width);
        make.height.equalTo(myBtn1.mas_height);
        make.bottom.equalTo(myBtn1.mas_bottom);
        //            make.right.equalTo(myBtn3.mas_right).offset(-20);
    }];
    
    [myBtn3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(myBtn2.mas_right);
        make.width.equalTo(myBtn2.mas_width);
        make.height.equalTo(myBtn2.mas_height);
        make.bottom.equalTo(myBtn2.mas_bottom);
        make.right.equalTo(baseView.mas_right).offset(-0);
    }];
    
    
    [myBtn setImage:[UIImage imageNamed:@"edus_see_Scan"] forState:UIControlStateNormal];
    [myBtn1 setImage:[UIImage imageNamed:@"edus_see_form"] forState:UIControlStateNormal];
    [myBtn2 setImage:[UIImage imageNamed:@"edus_see_news"] forState:UIControlStateNormal];
    [myBtn3 setImage:[UIImage imageNamed:@"edus_see_set"] forState:UIControlStateNormal];
    
    
    [myBtn setTitleColor:[UIColor colorWithHex:0x808080] forState:UIControlStateNormal];
    [myBtn1 setTitleColor:[UIColor colorWithHex:0x808080] forState:UIControlStateNormal];
    [myBtn2 setTitleColor:[UIColor colorWithHex:0x808080] forState:UIControlStateNormal];
    [myBtn3 setTitleColor:[UIColor colorWithHex:0x808080] forState:UIControlStateNormal];
    UIButton *nameCellBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [StuSuperView addSubview:nameCellBtn];
    [nameCellBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(StuSuperView.mas_bottom);
        make.height.equalTo(@(160/2));
        make.left.equalTo(StuSuperView.mas_left);
        make.right.equalTo(StuSuperView.mas_right);
    }];
    nameCellBtn.backgroundColor = [UIColor whiteColor];
    
    

    // 目前没用上 ， 名称 点击事件
    if(self.delegate){
        [nameCellBtn addTarget:self.delegate action:@selector(nameCellBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }

    UIImageView *im = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"task"]];
    [nameCellBtn addSubview:im];
    [im mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(nameCellBtn.mas_left).offset(30/2);
        make.centerY.equalTo(nameCellBtn.mas_centerY);
    }];
    UILabel *nameLabel = [[UILabel alloc] init];
    [nameCellBtn addSubview:nameLabel];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(nameCellBtn.mas_top).offset(42/2);
        make.height.equalTo(@(30/2));
        make.left.equalTo(im.mas_right).offset(26/2);
    }];
    [nameLabel sizeToFit];
    
    
    nameLabel.text = @"待办任务";
    nameLabel.textColor = [UIColor colorWithHex:0x333333];
    nameLabel.font = [UIFont systemFontOfSize:32/2];
    
    
    UILabel *KindStuLabel = [[UILabel alloc] init];
    [nameCellBtn addSubview:KindStuLabel];
    [KindStuLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(nameLabel.mas_bottom).offset(16/2);
        make.left.equalTo(nameLabel.mas_left);
        make.height.equalTo(@(26/2));
    }];
    [KindStuLabel sizeToFit];
    NSDate* date = [[NSDate alloc] initWithTimeIntervalSinceNow:0];
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"MM/dd"];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *comp = [calendar components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit | NSDayCalendarUnit fromDate:date];
    NSInteger weekDay = [comp weekday];
    NSLog(@"选中周是周几%zd",weekDay);
    NSString *str = [df stringFromDate:date];
    NSString *weekStr;
    if (weekDay == 1) {
        weekStr = @"星期日";
    }else{
        switch (weekDay) {
            case 2:
                weekStr = @"星期一";
                break;
            case 3:
                weekStr = @"星期二";
                break;
            case 4:
                weekStr = @"星期三";
                break;
            case 5:
                weekStr = @"星期四";
                break;
            case 6:
                weekStr = @"星期五";
                break;
            case 7:
                weekStr = @"星期六";
                break;
            default:
                break;
        }
    }
    KindStuLabel.text = [NSString stringWithFormat:@"%@ %@", str,weekStr];
    KindStuLabel.font = [UIFont systemFontOfSize:28/2];
    KindStuLabel.textColor = [UIColor colorWithHex:0xa1abb3];
    UIView *bgView = [[UIView alloc] init];
    [StuSuperView addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(nameCellBtn.mas_top);
        make.height.equalTo(@(10/2));
        make.left.equalTo(StuSuperView.mas_left);
        make.right.equalTo(StuSuperView.mas_right);
        
    }];
    bgView.backgroundColor = [UIColor colorWithHex:0xf7f7f7];
    
    
    
    
    return StuSuperView;
}

-(void)btnClick:(MyButtonMainPage *)btn{
    if (_delegate && [_delegate respondsToSelector:@selector(btnClick:)]) {
        [_delegate btnClick:btn];
    }
    
}

/**
 *    UIView *StuSuperView = [[UIView alloc]init];
 
 UIView *baseView = [[UIView alloc]init];
 baseView.backgroundColor = [UIColor whiteColor];
 
 [StuSuperView addSubview:baseView];
 [baseView mas_makeConstraints:^(MASConstraintMaker *make) {
 make.height.equalTo(@(200/2));
 make.left.equalTo(StuSuperView.mas_left);
 make.right.equalTo(StuSuperView.mas_right);
 make.top.equalTo(StuSuperView.mas_top);
 }];
 MyButtonMainPage *myBtn = [[MyButtonMainPage alloc]init];
 myBtn.Btntag = 0;
 [baseView addSubview:myBtn];
 
 MyButtonMainPage *myBtn1 = [[MyButtonMainPage alloc]init];
 myBtn1.Btntag = 1;
 [baseView addSubview:myBtn1];
 
 MyButtonMainPage *myBtn2 = [[MyButtonMainPage alloc]init];
 myBtn2.Btntag = 2;
 [baseView addSubview:myBtn2];
 
 MyButtonMainPage *myBtn3 = [[MyButtonMainPage alloc]init];
 myBtn3.Btntag = 3;
 [baseView addSubview:myBtn3];
 
 [myBtn setTitle:@"扫码考勤" forState:UIControlStateNormal];
 [myBtn1 setTitle:@"报表管理" forState:UIControlStateNormal];
 [myBtn2 setTitle:@"消息提醒" forState:UIControlStateNormal];
 [myBtn3 setTitle:@"系统设置" forState:UIControlStateNormal];
 
 
 
 myBtn.titleLabel.font = [UIFont systemFontOfSize:28/2];
 myBtn1.titleLabel.font = [UIFont systemFontOfSize:28/2];
 myBtn2.titleLabel.font = [UIFont systemFontOfSize:28/2];
 myBtn3.titleLabel.font = [UIFont systemFontOfSize:28/2];
 
 [myBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
 [myBtn1 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
 [myBtn2 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
 [myBtn3 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
 
 
 //    myBtn.backgroundColor = [UIColor blueColor];
 //    myBtn1.backgroundColor = [UIColor redColor];
 //    myBtn2.backgroundColor = [UIColor grayColor];
 [myBtn mas_makeConstraints:^(MASConstraintMaker *make) {
 make.left.equalTo(baseView.mas_left).offset(0);
 make.width.equalTo(myBtn1.mas_width);
 make.height.equalTo(@((190)/2));
 make.top.equalTo(StuSuperView.mas_top);
 //             make.bottom.equalTo(baseView.mas_bottom).offset(-20);
 
 }];
 [myBtn1 mas_makeConstraints:^(MASConstraintMaker *make) {
 make.left.equalTo(myBtn.mas_right);
 make.width.equalTo(myBtn.mas_width);
 make.height.equalTo(myBtn.mas_height);
 make.bottom.equalTo(myBtn.mas_bottom);
 }];
 
 [myBtn2 mas_makeConstraints:^(MASConstraintMaker *make) {
 make.left.equalTo(myBtn1.mas_right);
 make.width.equalTo(myBtn1.mas_width);
 make.height.equalTo(myBtn1.mas_height);
 make.bottom.equalTo(myBtn1.mas_bottom);
 //            make.right.equalTo(myBtn3.mas_right).offset(-20);
 }];
 
 [myBtn3 mas_makeConstraints:^(MASConstraintMaker *make) {
 make.left.equalTo(myBtn2.mas_right);
 make.width.equalTo(myBtn2.mas_width);
 make.height.equalTo(myBtn2.mas_height);
 make.bottom.equalTo(myBtn2.mas_bottom);
 make.right.equalTo(baseView.mas_right).offset(-0);
 }];
 
 
 [myBtn setImage:[UIImage imageNamed:@"edus_see_Scan"] forState:UIControlStateNormal];
 [myBtn1 setImage:[UIImage imageNamed:@"edus_see_form"] forState:UIControlStateNormal];
 [myBtn2 setImage:[UIImage imageNamed:@"edus_see_news"] forState:UIControlStateNormal];
 [myBtn3 setImage:[UIImage imageNamed:@"edus_see_set"] forState:UIControlStateNormal];
 
 
 [myBtn setTitleColor:[UIColor colorWithHex:0x808080] forState:UIControlStateNormal];
 [myBtn1 setTitleColor:[UIColor colorWithHex:0x808080] forState:UIControlStateNormal];
 [myBtn2 setTitleColor:[UIColor colorWithHex:0x808080] forState:UIControlStateNormal];
 [myBtn3 setTitleColor:[UIColor colorWithHex:0x808080] forState:UIControlStateNormal];
 UIButton *nameCellBtn = [UIButton buttonWithType:UIButtonTypeCustom];
 [StuSuperView addSubview:nameCellBtn];
 [nameCellBtn mas_makeConstraints:^(MASConstraintMaker *make) {
 make.bottom.equalTo(StuSuperView.mas_bottom);
 make.height.equalTo(@(160/2));
 make.left.equalTo(StuSuperView.mas_left);
 make.right.equalTo(StuSuperView.mas_right);
 }];
 nameCellBtn.backgroundColor = [UIColor whiteColor];
 [nameCellBtn addTarget:self action:@selector(nameCellBtnClick:) forControlEvents:UIControlEventTouchUpInside];
 
 UIImageView *im = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"stu_see_portrait_normal"]];
 [nameCellBtn addSubview:im];
 [im mas_makeConstraints:^(MASConstraintMaker *make) {
 make.left.equalTo(nameCellBtn.mas_left).offset(30/2);
 make.centerY.equalTo(nameCellBtn.mas_centerY);
 }];
 UILabel *nameLabel = [[UILabel alloc] init];
 [nameCellBtn addSubview:nameLabel];
 [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
 make.top.equalTo(nameCellBtn.mas_top).offset(20/2);
 make.height.equalTo(@(30/2));
 make.left.equalTo(im.mas_right).offset(30/2);
 }];
 [nameLabel sizeToFit];
 NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
 NSString *StuName = [ud objectForKey:@"username"];
 if (StuName) {
 nameLabel.text = StuName;
 }else{
 nameLabel.text = @"李小明";
 }
 
 nameLabel.textColor = [UIColor colorWithHex:0x333333];
 nameLabel.font = [UIFont systemFontOfSize:30/2];
 
 
 UILabel *KindStuLabel = [[UILabel alloc] init];
 [nameCellBtn addSubview:KindStuLabel];
 [KindStuLabel mas_makeConstraints:^(MASConstraintMaker *make) {
 make.top.equalTo(nameLabel.mas_bottom).offset(16/2);
 make.left.equalTo(nameLabel.mas_left);
 make.height.equalTo(@(26/2));
 }];
 [KindStuLabel sizeToFit];
 
 KindStuLabel.text = @"正式学员";
 KindStuLabel.textColor = [UIColor colorWithHex:0xafafaf];
 UIView *bgView = [[UIView alloc] init];
 [StuSuperView addSubview:bgView];
 [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
 make.bottom.equalTo(nameCellBtn.mas_top);
 make.height.equalTo(@(10/2));
 make.left.equalTo(StuSuperView.mas_left);
 make.right.equalTo(StuSuperView.mas_right);
 
 }];
 bgView.backgroundColor = [UIColor colorWithHex:0xf7f7f7];
 
 
 
 
 return StuSuperView;

 */
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
